/*******************************************************************\
*	file: 		ATPReceive.c										*
*	version:	1.06§												*
*																	*
* return any responses that were received via the GetRequest queue	*
* 																	*
* -----------------------------------------------------------------	*
* By:	Donald Koscheka, Greg Kimberly								*
* Date:	24-Sept-87													*
* ©	Copyright 1987, Apple Computer, Inc.							*
*	All Rights Reserved												*
*																	*
* -----------------------------------------------------------------	*
*						Modification History						*
* -----------------------------------------------------------------	*
*  Date	   	| By	|	 				Description					*
* -----------------------------------------------------------------	*
* 25-Sep-87	| GK	| file created									*
*  5-Nov-87	| DK	| added return result							*
* 21-Dec-87	| DK	| if response meesage is empty, set handle to 0	*
* 11-Jan-88	| DK	| modified to reflect decoupling of ATP & NBP	*
* 10-Feb-88	| DK	| added a checkpoint flag that receive sets to 	*
*			| 		| tell close not to call (because ATPClose can	*
*			| 		| called from a callback).						*
* -----------------------------------------------------------------	*
\*******************************************************************/

/*******************************************************************\
							Build Sequence
	
C -q2 -g -o "{hpo}"ATPReceive.c.o "{atp}"ATPReceive.c
	link  -sn Main=ATPReceive -sn STDIO=ATPReceive ¶
		 -sn INTENV=ATPReceive -rt XCMD=304 ¶
		 -m ATPRECEIVE ¶
		 "{hpo}"ATPReceive.c.o  "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ¶
		 "{CLibraries}"CInterface.o ¶
		 "{Libraries}"Interface.o ¶
		 -o "{hp}"HyperPeople

\*******************************************************************/

#include <Types.h>
#include <Memory.h>
#include <Resources.h>
#include <OSUtils.h>
#include <appleTalk.h>
#include <HyperXCmd.h>
#include <atalkXCMD.h>
#include <XCMDUtils.h>


pascal void ATPReceive(paramPtr)
	XCmdBlockPtr	paramPtr;
/*********************************
* ATReceive()
*
* Receive handle requests on the server side
* and responses on the client side.  If a
* queued request completes, hypercard is called
* back with the message.
*
* In:	paramPtr->params[0] == message to send on getrequest 
*								
* Out:	OSErr.
*
*********************************/
{
	ATPBlock	*atp;
	short		nextelem;
	short		result = NO_ERROR;
	Handle		rMess;
	
	atp = (ATPBlock *)RetrieveHandle( paramPtr, GLOBALATPDATA );
	
	if( !atp ){
		paramPtr->returnValue = ErrorReturn(  result );
		return;
	}
	
	atp->checkPoint = RECEIVING;
	
	rMess = paramPtr->params[0];
	if( !rMess || !**rMess )
		rMess = nil;
	
	
	result = PollRequests( paramPtr, atp, rMess );
	
	if( atp->checkPoint == CLOSE_NOW ){	/*** ATPClose was called from a callback ***/
		result = ATPKill( atp );
		SaveHandle( paramPtr, GLOBALATPDATA, nil );
	}
	else
		atp->checkPoint = CLOSE_OK;
		
	paramPtr->returnValue = ErrorReturn(  result );
}


